package com.tanguy.driver.ui.window

import android.content.Context
import android.view.View
import com.tanguy.driver.R
import com.tanguy.driver.base.BasePopupWindow
import com.tanguy.driver.utlis.extend.getSelectedItemString
import com.tanguy.user.utlis.extend.click
import com.weigan.loopview.LoopView
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/10/30 0030 11:09
 * 单个条目的选择器
 */
class OnePickerViewPopupWindow(context: Context, private var stringOne: List<String>, private val sureClick: (pos: Int, msg: String?) -> Unit) : BasePopupWindow(context) {
    override fun setContentRes(): Int = R.layout.popup_picker_view
    private lateinit var mLoopOne: LoopView
    override fun setBackgroundAlpha(): Float = 0.7f
    override fun initView(view: View) {
        super.initView(view)
        view.apply {
            mLoopOne = find(R.id.lv_pop_one)
            click(R.id.tv_select_cancel) { this@OnePickerViewPopupWindow.dismiss() }
            click(R.id.tv_select_confirm) {
                sureClick.invoke(mLoopOne.selectedItem, mLoopOne.getSelectedItemString())
                this@OnePickerViewPopupWindow.dismiss()
            }
        }

    }

    override fun initEvent() {
        super.initEvent()
        initLoopOne()
    }

    private fun initLoopOne() {
        mLoopOne.setItems(stringOne)
        mLoopOne.setNotLoop()
        mLoopOne.setInitPosition(0)
        mLoopOne.setTextSize(20f)
    }


}